package com.echo.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.echo.activity.R;
import com.echo.util.ScreenUtils;

/**
 * Created by EchoGe on 2016/6/11.
 */
public class LoadingDialog {
    private Context mContext;
    private Dialog mDialog;
    private TextView mLoadingMsg;

    public LoadingDialog(Context context){
        this.mContext=context;
        builder();
    }

    public LoadingDialog builder() {
        View view = LayoutInflater.from(mContext).inflate(
                R.layout.dialog_common, null);

        mLoadingMsg= (TextView) view.findViewById(R.id.dialog_loading_msg);

        mDialog = new Dialog(mContext, R.style.AlertDialogStyle);
        mDialog.setContentView(view);

        view.setLayoutParams(new FrameLayout.LayoutParams((int) (ScreenUtils.getScreenWidth(mContext) * 0.85), LinearLayout.LayoutParams.WRAP_CONTENT));

        return this;
    }

    public LoadingDialog setMsg(String msg) {
        if ("".equals(msg)) {
            mLoadingMsg.setText(R.string.dialog_no_msg);
        } else {
            mLoadingMsg.setText(msg);
        }
        return this;
    }

    public void show() {
        mDialog.show();
    }

    public void dismiss() {
        mDialog.dismiss();
    }
}
